import Vue from 'vue'
import Vuex from 'vuex'
import qs from "qs";
import {delCookie,getCookie,setCookie} from '../utils/util'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    login:  getCookie('login'),
    userInfo: qs.stringify(getCookie('userInfo')),
    mySayList: qs.stringify(getCookie('mySayList'))
  },
  mutations: {
    SET_Login: (state,login)=>{
      state.login = login
      setCookie('login',login)
    },
    set_userInfo: (state,userInfo) => {
      state.userInfo = userInfo
      setCookie('userInfo',userInfo)
    },
    set_mySayList: (state,mySayList) => {
      state.mySayList = mySayList;
      localStorage.setItem('mySayList',JSON.stringify(mySayList))
    }
  },
  getters: {
    getLogin: state => state.login,
    getUserInfo: state => state.userInfo ||{},
    getMySayList: state => state.mySayList || []
  },
  actions: {
  },
  modules: {
  }
})
